package com.huifer.wgx.spec;

import com.huifer.wgx.wgxenum.LineType;
import com.huifer.wgx.wgxenum.PointType;
import javax.sound.sampled.Line;
import org.aspectj.apache.bcel.generic.RET;

/**
 * <p>Title : PointLineTypeSpec </p>
 * <p>Description : 点类型判断,线段类型判断</p>
 *
 * @author huifer
 * @date 2019-03-22
 */
public class PointLineTypeSpec {

    private static final String CSK_MATCH = ".*csk\\d+$|.*CSK\\d+$";
    private static final String YSJ_MATCH = ".*p\\d+y\\d+$|.*P\\d+Y\\d+$";
    private static final String JCJ_MATCH = ".*p\\d+$|.*P\\d+$";
    private static final String WSJ_MATCH = ".*w\\d+$|.*W\\d+$";
    private static final String WSB_MATCH = ".*w\\d+y\\d+$|.*W\\d+Y\\d+$";

    /***
     * 判断井的类别
     * @param pointName 点名
     * @return 点类型
     */
    public static PointType pointType(String pointName) {
        if (pointName.matches(CSK_MATCH)) {
            return PointType.CSK;
        } else if (pointName.matches(YSJ_MATCH)) {
            return PointType.YSJ;
        } else if (pointName.matches(JCJ_MATCH)) {
            return PointType.JCJ;
        } else if (pointName.matches(WSJ_MATCH)) {
            return PointType.WSJ;
        } else if (pointName.matches(WSB_MATCH)) {
            return PointType.WSB;
        }
        return null;
    }


    public static LineType lineType(String startName, String endName) {
        PointType startType = pointType(startName);
        PointType endType = pointType(endName);
        assert startType != null;
        assert endType != null;
        if (startType.equals(PointType.CSK) || endType.equals(PointType.CSK)) {
            return LineType.YSG;
        } else if (startType.equals(PointType.JCJ) && endType.equals(PointType.JCJ)) {
            return LineType.YSG;
        } else if (startType.equals(PointType.YSJ) || endType.equals(PointType.YSJ)) {
            return LineType.HCG;
        } else if (startType.equals(PointType.WSJ) && endType.equals(PointType.WSJ)) {
            return LineType.WSG;
        } else if (startType.equals(PointType.WSB) || endType.equals(PointType.WSB)) {
            return LineType.WSG;
        }

        return null;

    }


}
